#include <iostream>

using namespace std;

struct student
{
    int no;
    char name[20];
    int engscore;
    int mathscore;
    int chscore;
    int all;
    int average;
};

void sort(struct student a[]);

int main ()
{
    struct student A[3];
    int i;

    for(i=0;i<3;i++)
    {
        cout<<endl<<"enter the information of student"<<i+1;
        cin>>A[i].no>>A[i].name>>A[i].engscore>>A[i].mathscore>>A[i].chscore;
    }

    for(i=0;i<3;i++)
    {
        A[i].all=A[i].chscore+A[i].engscore+A[i].mathscore;
        A[i].average=A[i].all/3.0;
    }

    sort(A);

    for(i=0;i<3;i++)
    {
        cout<<A[i].no<<" "<<A[i].name<<" "<<A[i].mathscore<<" "<<A[i].engscore<<" "<<A[i].chscore<<" "<<A[i].all<<endl;
    }

    cin>>i;
    return 0;
}

void sort (struct student a[])
{
    struct student t;
    int i,j;

    for(i=0;i<3-1;i++)
    {
        for(j=i+1;j<3;j++)
        {
            if(a[i].all<a[j].all)
            {
                t=a[i];
                a[i]=a[j];
                a[j]=t;
            }
            else if((a[i].all==a[j].all)&&(a[i].no<a[j].no))

            {
                t=a[i];
                a[i]=a[j];
                a[j]=t;
            }
        }
    }
}
